package com.fowo.api.service.handleWork;

import com.fowo.api.entity.Receivable;
import com.fowo.api.model.receivable.ReceivableReceivableApproveAction;
import com.fowo.api.service.impl.ReceivableProductServiceImpl;
import com.fowo.api.service.impl.ReceivableServiceImpl;
import com.fowo.api.user.model.JwtUserInfo;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import javax.annotation.Resource;

@Component
public class receivableReceivableApprove implements ReceivableReceivableApproveAction {

    @Resource
    private ReceivableServiceImpl receivableService;

    @Override
    public void run(Long id) throws Exception {
        JwtUserInfo jwtUserInfo = JwtUserInfo.fromHeader();
        Receivable byId = receivableService.getById(id);
        Assert.notNull(byId,"应收单不存在");
        Assert.isTrue(byId.getStatus().equals("0"),"违规操作!");
        byId.setStatus("1");
        byId.setVerifier(jwtUserInfo.getUserId());
        receivableService.updateById(byId);
    }
}
